<template>
  <div class="AuthInfo-container">
    <title-name title="角色信息"></title-name>
    <div class="table-operateors mb20">
      <a-button
        type="primary"
        @click="showAuthTree"
      >综合权限信息</a-button>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :alert="true"
      show-size-changer
      show-quick-jumper
      :showPagination="false"
    >
      <template
        slot="sort"
        slot-scope="text, record, index"
      >
        <span>{{ index + 1 }}</span>
      </template>
      <template
        slot="action"
        slot-scope="text, record"
      >
        <a
          class="base-btn"
          @click="handleUpdate('look', record)"
        >查看</a>
      </template>
    </s-table>
    <AddResource
      look="look"
      :id="childInitData.roleId"
      :userId="childInitData.userId"
      ref="addResourceRefs"
      orgin="person"
      title="权限信息"
    />
  </div>
</template>

<script>
import { clientId } from '@/config'
import { getRoleListByUser } from '@/api/system/menuAndAuth.js'
import AddResource from '@/views/systemManage/menuPermissions/systemRoleManage/AddResource.vue'
import { STable } from '@/components'
const columns = [
  {
    title: '序号',
    dataIndex: 'sort',
    scopedSlots: { customRender: 'sort' }
  },
  {
    title: '角色名称',
    dataIndex: 'name'
  },
  {
    title: '编码',
    dataIndex: 'code'
  },
  {
    title: '业务标识',
    dataIndex: 'commandName'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'AuthInfo',
  components: {
    STable,
    AddResource
  },
  props: {
    userId: {
      type: String,
      default: ''
    },
    roleId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      childInitData: {},
      visibleState: {
        authTreeModal: false
      },
      columns,
      queryParam: {
        clientId
      }
    }
  },
  methods: {
    close() {
      this.childInitData = {
        userId: ""
      }
    },
    showAuthTree() {
      this.childInitData = {
        userId: this.userId
      }
      // this.visibleState.authTreeModal = true
      this.$refs.addResourceRefs.open()
    },
    handleUpdate(type, data = {}) {
      this.childInitData = {
        roleId: data.id
      }
      this.$refs.addResourceRefs.open()
    },
    async loadData(parameter) {
      const requestParameters = Object.assign({}, parameter, this.queryParam, { userId: this.userId })
      return getRoleListByUser(requestParameters)
    }
  }
}
</script>

<style>
</style>
